import React from 'react'
import { ROOTURL } from './AppConfig'
export default class Forum extends React.Component{
    constructor(props) {
        super(props)
        this.state = { topiccategorys: [] }
        fetch(ROOTURL + 'topiccategorys.php').then(
            response => response.json()
        ).then(json => {
            this.setState({
                topiccategorys: json.result
            })
        }).catch(
            error => { alert('网络错误无法加载话题: ' + error.toString()) }
        )
    }
    render() {
        const topicList = this.state.topiccategorys.map((item) => {
            return (
                <div className="forumItem" key={item.type}>
                    <div className="forumItemText">
                        <div>{item.title}</div>
                        <div>{item.subtitle}</div>
                    </div>
                    <div className="forumItemLayer"/>
                    {item.icon != '' && <img src={item.icon} className="forumItemImage" />}
                </div>
            )
        })
        return (
            <div>
                {topicList}
            </div>
            )
    }
}